package com.example.sxproject.mapper;

import com.example.sxproject.pojo.Company;
import com.example.sxproject.pojo.FinancialProduct;
import com.example.sxproject.pojo.FinancialUser;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Mapper
@Repository

public interface CompanyMapper {

    //查询select：查询全部
    @Select("select * from company")
    List<Company> selectAll();

    // 根据城市查询对应的公司列表
    @Select("SELECT * FROM Company WHERE city = #{city}")
    List<Company> findCompaniesByCity(String city);

    // 根据公司账户查询对应的公司列表
    @Select("SELECT * FROM Company WHERE companyCount = #{companyCount}")
    Company findByCount(String companyCount);

    // 根据公司名称查询对应的公司列表
    @Select("SELECT * FROM Company WHERE companyName LIKE CONCAT('%', #{search}, '%')")
    List<Company> searchCompany(String search);


    @Select("SELECT * FROM company WHERE city = #{city} AND companyName = #{companyName}")
    Company findByCityAndCompanyName(String city, String companyName);


    //添加insert：添加公司
    @Insert("insert into company" +
            "( companyName, city, companyType, companyCount, companyStatus)" +
            " values (#{companyName}, #{city}, #{companyType}, #{companyCount}, '1')")
    void addCompany(Company company);

    //更新update：更新公司信息
    @Update("update company set companyName = #{companyName}, city = #{city}," +
            "companyType = #{companyType}, companyCount = #{companyCount}" +
            "where id = #{id}")
    void updateCompany(Company company);

    //更新update：实现假删除
    @Update("update company set companyStatus = #{companyStatus} " +
            "where id = #{id}")
    void deleteCompany(Company company);

    //管理员查询
    @Select({
            "<script>",
            "SELECT *",
            "FROM company",
            "<where>",
            "<if test='city!= null'>",
            "city=#{city}",
            "</if>",
            "<if test='companyType!= null'>",
            "AND companyType = #{companyType}",
            "</if>",
            "</where>",
            "</script>",
    })
    List<Company> selectCompanyByCT(Company company);


    //管理员注销公司
    @Update("update company set companyStatus = '2' " +
            "where id = #{id}")
    void companyDel(Integer id);


}
